import java.util.Stack;

public class MinStack {
    public Stack<Integer> stack;
    public Stack<Integer> minStack;

    public MinStack(){
        stack=new Stack<>();
        minStack=new Stack<>();
    }

    public void push(int val){
        stack.push(val);
        if (minStack.empty()){
            minStack.push(val);
        }else {
            if (val<=minStack.peek()){
                minStack.push(val);
            }
        }
    }
    public void pop(){
        int popVal=stack.pop();
        if (popVal==minStack.peek()){
            minStack.pop();
        }
    }
    //相当于peek()方法
    public int top(){
        return stack.peek();
    }
    //获取栈中最小的元素
    public int getMin(){
        return minStack.peek();
    }
}
